package net.cmbt.okframework_demo;

import android.net.Uri;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.util.Log;
import android.view.KeyEvent;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.webkit.JsResult;
import android.webkit.ValueCallback;
import android.webkit.WebChromeClient;
import android.webkit.WebView;
import android.widget.Toast;

import net.cmbt.okframe.okbanner.BannerListener;
import net.cmbt.okframe.okbanner.OKBannerNormal;
import net.cmbt.okframe.okbanner.OkIndicatorNormal;
import net.cmbt.okframe.oknet.OkHttpListener;
import net.cmbt.okframe.oknet.OkhttpTools;
import net.cmbt.okframe.okwebview.SuperWebView;
import net.cmbt.okframe.okwebview.UpDownFileManager;
import net.cmbt.okframe.okwebview.WebCacheManager;
import net.cmbt.okframe.okwebview.inteface.SwebLoadListener;
import net.cmbt.okframe.okwebview.view.SuperWebLayout;

import java.io.IOException;
import java.util.ArrayList;
import java.util.HashMap;

/**
 * Created by LG on 2019/12/11.
 */

public class DemoFragment extends Fragment implements SwebLoadListener {

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        View view = inflater.inflate(R.layout.demo_fragment, container, false);

        OKBannerNormal okBannerNormal = (OKBannerNormal) view.findViewById(R.id.oknormal);
        OkIndicatorNormal okIndicator = (OkIndicatorNormal) view.findViewById(R.id.okindicator);
        SuperWebLayout superWebLayout = (SuperWebLayout) view.findViewById(R.id.suerlayout);

        ArrayList<String> list = new ArrayList<>();
        list.add("https://img.51miz.com/Photo/2018/02/08/01/P1328310_9911673c7a32c5853f2ed1d0af526a6e.jpg!/quality/90/unsharp/true/compress/true/format/webp/fh/630");
        list.add("https://img.51miz.com/Photo/2017/06/28/02/P1228277_3b23f0ac01a8f34b92886b6e7fa441dc.jpg!/quality/90/unsharp/true/compress/true/format/webp/fh/630");
        list.add("https://img.51miz.com/Element/00/73/99/54/71d276c5_E739954_06abed57.jpg!/quality/90/unsharp/true/compress/true/format/jpg/fh/630");
        list.add("https://img.51miz.com/Element/00/73/99/48/04a36998_E739948_767a87b4.jpg!/quality/90/unsharp/true/compress/true/format/jpg/fh/630");
        okBannerNormal.buildBanner(list, okIndicator, true, 3000)
                .setBannerListener(new BannerListener() {
                    @Override
                    public void onClick(int postion, View view) {
                        Toast.makeText(getActivity(), "" + postion, Toast.LENGTH_SHORT).show();
                    }
                });


        SuperWebView build = new SuperWebView.Builder().setUseGoBack(true)
                .setBuiltInZoomControls(true)
                .setSupportAccessFiles(true)
                .setSupportCallSMS(true)
                .setSupportImgLongClick(true)
                .setSupportJS(true)
                .setWebCacheManager(new WebCacheManager())
                .setUpDownFileManager(new UpDownFileManager())
                .setUrl("https://gitee.com/CeMaBenTeng/fast_development_framework")
                .build();
        superWebLayout.with(build, this);


        OkhttpTools okhttpTools = new OkhttpTools(getActivity(), 100, new OkHttpListener() {
            @Override
            public void onSuccess(int requestCode, String result, String request) {

                if (requestCode == 100) {
                    Log.e("", "" + result);
                }

                if (requestCode == 200) {
                    Log.e("", "" + result);
                }
            }

            @Override
            public void onError(int requestCode, IOException exception) {

            }
        });


        okhttpTools.get(100, "https://www.meicanjixiang.com/AndroidProgram/GetDishes?procode=5627919025905892893");
        HashMap<String, String> map = new HashMap<>();
        map.put("id", "12");
        map.put("need_ad", "1");
        okhttpTools.postForm(200, "https://api.watcn.com//api/nav/info", map);

        return view;
    }


    @Override
    public void goBackListener(View v, int keyCode, KeyEvent event) {

    }

    @Override
    public void onDownloadStart(String url, String s1, String s2, String s3, long l) {

    }

    @Override
    public void onSeleLocFileListener(Uri uri) {

    }

    @Override
    public void onJsAlert(WebView view, String url, String message, JsResult result) {

    }

    @Override
    public void onShowFileChooser(WebView webView, ValueCallback<Uri[]> filePath, WebChromeClient.FileChooserParams fileChooserParams) {

    }

    @Override
    public void onProgressChanged(WebView view, int newProgress) {

    }

}
